#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>

#include <arpa/inet.h>

#include <netdb.h>
#include <netinet/in.h>

#include <sys/types.h>
#include <sys/socket.h>

#define SERVEURNAME "127.0.0.1"

#include <cedule/log.h>

#include "client.h"
#include "config.h"

int main(int argc, char ** argv)
{
	Config_t * config;
	Client_t * client;

	config = config_create();
	config_parse_cmdline( config, argc, argv );
	
	config_display( config );
	if ( ! config_is_valid( config ) ) {
		config_usage( argv[0] );
		exit( EXIT_FAILURE );
	}

	start_log( "cedule" );
	log_info("cedule started\n");

	client = client_create( config );
	if ( client_connect( client ) < 0 ){
		log_error( "Unable to connect." );
		goto error;
	}
	if ( client_auth( client ) < 0 ) {
		log_error( "Unable to authenticate." );
		goto error;
	}
	client_run( client );

	return EXIT_SUCCESS;

error:
	return EXIT_FAILURE;
};

